package com.wss.agent.maven.plugin.utils;

import java.util.Collection;

import org.apache.maven.model.Dependency;
import org.apache.maven.model.Exclusion;

import com.wss.agent.model.DependencyInfo;
import com.wss.agent.model.ExclusionInfo;

public class DependencyInfoBuilder {

	/* --- Static methods --- */

	/**
	 * The method builds the info model from the given dependency.
	 * 
	 * @param dependency Source maven dependency.
	 *  
	 * @return Extracted info model.
	 */
	public static DependencyInfo fromDependency(Dependency dependency) {
		DependencyInfo info = new DependencyInfo();

		// dependency data
		info.setGroupId(dependency.getGroupId());
		info.setArtifactId(dependency.getArtifactId());
		info.setVersion(dependency.getVersion());
		info.setScope(dependency.getScope());
		info.setClassifier(dependency.getClassifier());
		info.setOptional(dependency.isOptional());
		info.setType(dependency.getType());
		info.setSystemPath(dependency.getSystemPath());

		// exclusions
		Collection<ExclusionInfo> exclusions = info.getExclusions();
		for (Exclusion exclusion : dependency.getExclusions()) {
			exclusions.add(new ExclusionInfo(exclusion.getGroupId(), exclusion.getArtifactId()));
		}

		return info;
	}
}
